public class Demo02JMM {

    public static void main(String[] args) throws InterruptedException {
        JmmDemo jmmDemo = new JmmDemo();
        Thread thread = new Thread(jmmDemo);
        thread.start();
        Thread.sleep(100);
        jmmDemo.flag = false;
        System.out.println("已经修改为false");
        System.out.println(jmmDemo.flag);
    }

    static class JmmDemo implements Runnable {

        public boolean flag = true;
        public volatile boolean flag1 = true;

        @Override
        public void run() {
            System.out.println("子线程执行。。。。。");
            while(flag1){}
            System.out.println("子线程结束。。。。。");
        }
    }

}
